home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / utility / fgrep.zip / FGREP.DOC < prev    next >
Text File  |  1997-06-04  |  48KB  |  1,159 lines

  1.                                    FGREP 1.84
  2.                                    ----------
  3.  
  4.  
  5.  
  6.         Purpose
  7.         -------
  8.         FGREP (Fast GREP) is a small utility that can be used to find
  9.         strings of characters in ASCII text files, and arbitrary
  10.         sequences of bytes in other files.  String search capabilities
  11.         are not extensive (no regular expressions), but FGREP is small
  12.         and very, very fast.  FGREP is intended to replace the FIND
  13.         filter with something faster and more flexible.
  14.  
  15.         UNIX people: we fully realize that this isn't the grep or fgrep
  16.         with which you are familiar.  We know that the RE in GREP means
  17.         "regular expressions" and that we don't support regular
  18.         expressions.  However, the name serves to point people in the
  19.         right direction.  Please don't write to tell us that this "isn't
  20.         really fgrep".
  21.  
  22.  
  23.  
  24.         FGREP386
  25.         --------
  26.         FGREP386.COM is a version of FGREP.COM that requires an 80386
  27.         or better.  It should be slightly faster than FGREP.COM (don't
  28.         expect anything spectacular).  If you have an 80386 a higher
  29.         CPU, just erase FGREP.COM and rename FGREP386.COM to FGREP.COM.
  30.  
  31.  
  32.         New in version 1.84
  33.         -------------------
  34.         This is a bugfix release only.
  35.  
  36.  
  37.         Syntax
  38.         ------
  39.         FGREP's syntax is
  40.  
  41.                 FGREP [options] target {@file}
  42.  
  43.         There are many "options", but the most common use is very
  44.         simple:
  45.  
  46.                 FGREP hello myfile.txt
  47.  
  48.         This command would display all lines of MYFILE.TXT that contain
  49.         the character string "hello".
  50.  
  51.  
  52.         Targets
  53.         -------
  54.         The target is what you're looking for in the file.  There are
  55.         two ways to specify targets: as strings and as series of
  56.         hexadecimal bytes.  The two can be combined in a single target
  57.         specification.
  58.  
  59.         Strings are sequences of ASCII characters, like "hello".
  60.         Normally, you can just type in the string and forget it, but you
  61.         may have to "delimit" the string, i.e., bracket it by a pair of
  62.         matching non-alphanumeric characters (anything except '-' and
  63.         '$'):
  64.  
  65.             'string'
  66.             /string/
  67.             .string.
  68.  
  69.         Choose a delimiter that does not appear in the string.  This is
  70.         no good:
  71.  
  72.             'you've made a mistake'
  73.  
  74.         Delimiters are required for a string target if any of these four
  75.         conditions are met:
  76.  
  77.             -- it is combined with hex byte sequences (more below)
  78.             -- it contains spaces or tabs
  79.             -- it begins with a non-alphanumeric character
  80.             -- it contains the redirection characters < > |.
  81.  
  82.         In the last case, the string MUST be delimited by double quotes
  83.         ("), otherwise DOS will interpret it as redirection.
  84.  
  85.         Examples of valid string targets:
  86.  
  87.                 mov
  88.                 ax
  89.                 "two words"     (requires delimiter: contains a space)
  90.                 '/7'            (begins with non-alphanumeric)
  91.                 "f->x"          (contains ">", must use double quotes)
  92.  
  93.         It is always OK to delimit a string, even if delimiters are
  94.         unnecessary.
  95.  
  96.         REMEMBER that if the target contains DOS redirection characters
  97.         (<, >, or |), it MUST be delimited with double quotes ("") or
  98.         DOS will try to perform unwanted redirection.  For example:
  99.  
  100.             FGREP "a <= b" myfile.pas
  101.  
  102.         Hex byte sequences are used for binary file searching when the
  103.         bytes to be searched for are non-displayable characters or make
  104.         no sense as strings (e.g., program code).  They are specified as
  105.         pairs of hexadecimal bytes introduced by a leading '$':
  106.  
  107.             $EF
  108.             $CD21           (CDh, 21h)
  109.             $CD$21          (identical; either format is OK)
  110.             $00FFFE00       (00h, FFh, FEh, 00h)
  111.             $CD 21          (ILLEGAL: no spaces permitted)
  112.  
  113.         You can combine strings and hex sequences by using a '+':
  114.  
  115.             "abc"+$E74A+"def"
  116.  
  117.  
  118.         Target wildcards
  119.         ----------------
  120.         String targets (not hex targets) may contain one or more "?"
  121.         wildcards.  The ? will match any single non-null character in
  122.         the file.  E.g., "[?i]" will match "[si]", "[di]", etc., but not
  123.         "[i]".  Wildcards are not permitted when hex byte sequences are
  124.         used.
  125.  
  126.         If you want to search for the '?' character literally, use
  127.         '\?'.  For example, the target
  128.  
  129.                 what\?
  130.  
  131.         will search for the literal string "what?".
  132.  
  133.  
  134.         Specifying target files
  135.         -----------------------
  136.         You can list zero (see "Redirection"), one, or multiple files to
  137.         be searched.  Files listed may include DOS's * and ? wildcards.
  138.         Paths may be specified.  Examples:
  139.  
  140.             myfile.txt
  141.             *.txt
  142.             *.*
  143.             this.c that.c other.c
  144.             *.c *.pas
  145.             C:\UTIL\*.* D:\SYS\*.*
  146.             E:\LIBRARY\*.D?C
  147.  
  148.         You may also specify just a drive or directory name.  If you
  149.         specify just a drive, FGREP searches all files in the current
  150.         directory of the specified drive.  If you specify a directory
  151.         name, FGREP searches all files in the specified directory.
  152.         Examples:
  153.  
  154.             c:      [same as c:*.*]
  155.             c: d:   [same as c:*.* d:*.*]
  156.             \src    [same as \src\*.*]
  157.             d:\src  [same as d:\src\*.*]
  158.  
  159.         You can also search all subdirectories of the directories you
  160.         specify; see the discussion of the -r option in the "Options"
  161.         section below.
  162.  
  163.  
  164.         File lists
  165.         ----------
  166.         If the name of a file on the command line is prefixed with an
  167.         '@' character (e.g., '@list.txt'), the file is assumed to be a
  168.         text file containing the names of files to be searched.  For
  169.         example:
  170.  
  171.             fgrep hello @files.lst
  172.  
  173.         FGREP will assume that the file FILES.LST is a text file that
  174.         contains the names of files to be searched.  Each line of such a
  175.         file should contain the name(s) of one or more files to be
  176.         searched.  Files in file lists are specified exactly as are
  177.         files named on the command line, except that you can't use
  178.         another '@' file list; that is, file lists can't be nested.
  179.  
  180.         Here is an example of a valid list file:
  181.  
  182.             this.c
  183.             c:\c\*.c d:\c\*.c
  184.             d:\misc\*.txt
  185.  
  186.         The name specified for the list file cannot contain wildcards;
  187.         that is, this is illegal:
  188.  
  189.             fgrep hello @lists.*        (WRONG)
  190.  
  191.         If you want to search for text in a file whose name begins with
  192.         an '@', use a double '@'.  For example,
  193.  
  194.             fgrep hello @@foo.txt
  195.  
  196.         will search for 'hello' in the file @FOO.TXT.
  197.  
  198.  
  199.         Redirection
  200.         -----------
  201.         If no file is listed, FGREP will take its input from the
  202.         standard input device, allowing it to be used as a
  203.         filter. For example, the command:
  204.  
  205.             DIR | fgrep pas
  206.  
  207.         would display any lines from a directory listing that contain
  208.         the string "pas".  Or,
  209.  
  210.             DIR | fgrep "<dir>"
  211.  
  212.         would list all subdirectories of the current directory.
  213.  
  214.         This command:
  215.  
  216.             pkunzip -c myzip foo.txt | FGREP somestring
  217.  
  218.         would display all lines from the file FOO.TXT in the ZIP
  219.         file MYZIP that contain "somestring" (the -c option causes
  220.         PKUNZIP to extract FOO.TXT to the console device instead of to a
  221.         disk file).
  222.  
  223.         FGREP will terminate with an error if no file is listed and
  224.         standard input is not redirected.  Otherwise, it would be
  225.         silently waiting for keyboard input, possibly leading you to
  226.         believe that it had died.
  227.  
  228.  
  229.         Examples of use
  230.         ---------------
  231.         Here are some examples of FGREP use:
  232.  
  233.         1. List all lines of MYFILE.TXT containing "hello"
  234.  
  235.             FGREP hello myfile.txt
  236.  
  237.         2. List all lines of all *.C files in the current directory that
  238.         contain "include foo.c":
  239.  
  240.             FGREP "include foo.c"  *.c
  241.  
  242.         3. List all lines from FILEA.EXT, FILEB.EXT, and FILEC.EXT that
  243.         contain the string "abcd" followed by any character:
  244.  
  245.             FGREP abcd? filea.ext fileb.ext filec.ext
  246.  
  247.         4. Display occurrences of the byte CDh followed by 21h (a DOS
  248.         call) in the program MYPROG.EXE:
  249.  
  250.             FGREP $CD21 myprog.exe
  251.  
  252.         5. Display occurrences of the string "abc" followed by a byte of
  253.         zeroes in all files in the C:\UTIL and D:\SYS directories:
  254.  
  255.             FGREP 'abc' + $00 c:\util\*.* d:\sys\*.*
  256.  
  257.  
  258.         Output
  259.         ------
  260.         FGREP's default screen output looks like this:
  261.  
  262.                 **File <filename>
  263.                 [text of lines containing string]
  264.                 **File <filename>
  265.                 [text of lines containing string]
  266.  
  267.         You can add line numbers to the display by using the -l option
  268.         (see below).
  269.  
  270.         If the "Microsoft format" option (-m or -M, see below) is used,
  271.         the output is in this format:
  272.  
  273.                 filename(linenum): text
  274.  
  275.         This format is the standard format used by Microsoft (R)
  276.         language products and by its MEGREP.  If -m is used, only the
  277.         filename and extension are displayed; if -M is used, the
  278.         complete filespec, including path, is displayed.
  279.  
  280.         When a hex byte sequence or the -b switch is specified, FGREP
  281.         uses the binary output mode.  See below for details.
  282.  
  283.         All useful output is sent to the standard output device, so it
  284.         may be piped to other programs or redirected to file:
  285.  
  286.                 FGREP target filea | yourprog
  287.                 FGREP target filea > test.txt
  288.  
  289.         Error messages and the program logo will appear always appear on
  290.         the console device, and will never appear in redirected or piped
  291.         output (unless you use the -Zl option).
  292.  
  293.         FGREP returns an errorlevel to the operating system.  It will be
  294.         one of:
  295.  
  296.             0:   String not found in any file
  297.             1:   String found in at least one file
  298.             255: Error (file read error or bad parameter)
  299.  
  300.  
  301.         Options
  302.         -------
  303.         These are the option switches that control how FGREP works.  All
  304.         switches are case-insensitive except -m/M, -b/B, and -r/-R; for
  305.         example, either -a or -A will set ANSI mode.  All switches must
  306.         precede the target on the command line, but they may be in any
  307.         order.  If you specify conflicting switches, the last one will
  308.         be effective.
  309.  
  310.         Options may be specified on the command line or in an
  311.         environment variable (see below).
  312.  
  313.         -a is ANSI mode.  If you have ANSI.SYS (or equivalent)
  314.            installed, escape characters (ASCII 27) in displayed text
  315.            lines can cause odd results.  If you use the -A switch,
  316.            FGREP will substitute an upside-down question mark (¿) for
  317.            ESC, possibly resulting in cleaner displays.  You'll only
  318.            need this switch if you have ANSI installed and there are ESC
  319.            characters in the files you're scanning.  Ignored in binary
  320.            mode.
  321.  
  322.         -b specifies binary search mode/output.  This switch is
  323.            automatically set if you use a hex byte sequence in the
  324.            target.  See "binary search" below.
  325.  
  326.         -B specifies a case insensitive binary search.
  327.  
  328.         -c makes the search case sensitive ("String" will not match
  329.            "string" or "STRING").  Normally, FGREP ignores case.  This
  330.            switch is ignored in binary mode.  Using -c will generally
  331.            result in faster searches.
  332.  
  333.         -e specifies that ONLY an errorlevel is to be returned.
  334.            There will be no display at all.  This is equivalent to the
  335.            combination -s0.
  336.  
  337.         -f causes the "**File" header lines to be displayed only for
  338.            those files that contain the search string.
  339.  
  340.         -g gets a user-supplied character frequency table.  See
  341.            "Using your own frequency table" below.
  342.  
  343.         -i specifies an "input field" or "search field," allowing you
  344.            to search only a part of each line.  See "Limiting searches
  345.            to specified columns", below.
  346.  
  347.         -j left justifies output, i.e., removes any leading spaces
  348.            from output text.  Ignored in binary mode.
  349.  
  350.         -l adds line numbers to FGREP's output.  Ignored in binary mode.
  351.  
  352.         -m or -M specify Microsoft (R) output format.  See "Output"
  353.            above.  If -m is used, only the filename will appear.  If
  354.            -M is used, the full filespec (including drive and path)
  355.            will be included.  Unless the files being searched are on
  356.            CD-ROM drives, the path is "fully qualified", i.e., it
  357.            begins from the root directory and resolves any "." and
  358.            ".." references in your target file specification.  If the
  359.            files are on CD-ROM drives, the path may not be fully
  360.            qualified.
  361.  
  362.         -o specifies a maximum output width.  It should be followed by a
  363.            decimal number from 0 to 50000.  For example, -o40 causes
  364.            FGREP to truncate all output to a maximum of 40 characters per
  365.            line.  If you specify -o0, no text will be displayed at
  366.            all.  This is not useful for the normal display, but you
  367.            can use this feature with -l, -m, or -M if you want to
  368.            display just the line numbers where the text was found but
  369.            not the text itself.
  370.  
  371.            Do not confuse the "o" (Output) option with the "0" (zero
  372.            text) option.  -o is ignored in binary mode.
  373.  
  374.         -p pauses on full screen of output.
  375.  
  376.         -r recursive (subdirectory) search.  For each filespec provided,
  377.            FGREP searches the specified directory and all subdirectories
  378.            for matching file names.  If no directory is specified, FGREP
  379.            begins the search with the current directory.  For example:
  380.  
  381.                 fgrep -r "text" *.c d:\src\*.c
  382.  
  383.            This command searches all *.c files in the current directory
  384.            and all of its subdirectories; then it searches all *.c files
  385.            in D:\SRC and all of its subdirectories.
  386.  
  387.         -R another recursive search; differs from -r in that the top
  388.            level directory is NOT searched.  For example, if the
  389.            filename is specified on the command line as \WP\*.*,
  390.            fgrep will search the subdirectories of \WP but not \WP
  391.            itself.  This can be useful, for example, if you have
  392.            a text editor directory with document subdirectories and
  393.            you want to search only the documents (not the text editor
  394.            files themselves).
  395.  
  396.         -s suppresses the "**File" header lines in the output.
  397.  
  398.         -t displays only the actual text found (rather than the entire
  399.            line containing the text).  This is useful with wildcards;
  400.            for example, the command
  401.  
  402.                 fgrep -t "??rse" dict.txt
  403.  
  404.            might display "parse", "purse", "horse", etc. (perhaps
  405.            displaying all words from a text dictionary that match the
  406.            pattern). Note that the displayed text will be all lowercase
  407.            if the search is case insensitive; and, any embedded spaces
  408.            will be missing if the search is white space insensitive (-w
  409.            option).  -t and -v (reVerse search) are incompatible.
  410.  
  411.            You can combine -t with an input field and wildcards to
  412.            display "fields" of a file.  For example:
  413.  
  414.                 fgrep -t -i70,75 "??????" test.dat
  415.  
  416.            This command would display columns 70-75 of all lines in
  417.            the file.
  418.  
  419.         -v provides a reVerse or negative search.  That is, all lines
  420.            that do NOT contain the specified string are displayed.  This
  421.            provides a handy way to get rid of lines containing specified
  422.            text.  Suppose, for example, that you have a file containing
  423.            a list of file names, and you are interested in all files
  424.            EXCEPT those that contain a '$' in the name (perhaps they are
  425.            temporary files):
  426.  
  427.                 FGREP -v "$" filename
  428.  
  429.            This switch is ignored in binary mode.
  430.  
  431.         -w indicates that white space (blanks and tabs) is not
  432.            significant.  White space in both the search string and the
  433.            input file will be ignored.  If -w is specified, the wildcard
  434.            character (?) will match any nonblank character.  Ignored in
  435.            binary mode.
  436.  
  437.         -x suppresses the display of the program logo/copyright.
  438.  
  439.         -Za causes FGREP to echo its command line arguments to the
  440.            standard output device. This allows the parameters to be
  441.            captured in redirected output files and is intended mostly
  442.            for use by other programs that perform post-processing on
  443.            FGREP output.
  444.  
  445.         -Zb filter "bells" from output.  Before displaying the text of
  446.            lines containing the target string, FGREP changes any "bell"
  447.            characters (character 7) to spaces, which prevents the
  448.            system from beeping at you.
  449.  
  450.         -Zd causes FGREP to display the name of each directory as it
  451.            begins to search the directory.  This is intended mostly
  452.            for recursive searches (-r option).
  453.  
  454.         -Zl causes FGREP to send its logo to the standard output
  455.            device instead of the standard error device.  This allows
  456.            the logo and version number to be captured in redirected
  457.            output files and is intended mostly for use by other
  458.            programs that perform post-processing on FGREP output.
  459.  
  460.         -Zv tells FGREP to ignore the FGREP= environment variable (see
  461.            below).  If present, this must be the first option specified.
  462.  
  463.         -0 ("0" text lines) suppresses the display of lines of text
  464.            containing the specified string.  FGREP will skip immediately
  465.            to the next file when the string is found.  The -0 option
  466.            is most commonly used with -f (-f0) to simply display a list
  467.            of files containing the target string.
  468.  
  469.            Note that -0 is different in effect from -o0; when combined
  470.            with -l or -m, the -o0 option will display line numbers and/or
  471.            filenames, but -0 will display nothing.
  472.  
  473.         -1 ("1" text line) specifies that only the first line containing
  474.            containing the specified string in each file will be
  475.            displayed.  FGREP will then skip immediately to the next
  476.            file.
  477.  
  478.         -@ causes FGREP to display ONLY a list of files that contain
  479.            the search target.  No text is displayed or other information
  480.            is displayed.  This option is useful to create a file
  481.            containing a list of files for further processing by
  482.            other programs.  For example:
  483.  
  484.               FGREP -@ "stuff" *.txt > list.txt
  485.  
  486.            On completion of this run, the file LIST.TXT will contain
  487.            a list of the files that contain "stuff".
  488.  
  489.         -? causes FGREP to send its usage/help information to the
  490.            standard output device so that it can be piped or redirected.
  491.            The usage info is normally sent to the standard error device,
  492.            which can't be redirected.  Using -? allows you to pipe the
  493.            usage information through MORE or some other utility so that
  494.            you can review it (it's now longer than most screens will
  495.            be able to display).
  496.  
  497.         FGREP environment variable
  498.         --------------------------
  499.         You can place frequently-used options in an environment variable
  500.         named FGREP.  For example, if you always want output displayed
  501.         in "Microsoft" format:
  502.  
  503.               SET FGREP=-m
  504.  
  505.         This is equivalent to using the -m option in every FGREP
  506.         command.
  507.  
  508.         The -Zv option causes FGREP to ignore the contents of the FGREP
  509.         environment variable.  Use this when you don't want the options
  510.         set in the variable to affect a particular FGREP run.  For
  511.         example, the command
  512.  
  513.               FGREP -Zv foo *.txt
  514.  
  515.         would result in a standard format display even if FGREP= is set
  516.         as in the above example (SET FGREP=-m).
  517.  
  518.         If present, the -Zv options must be first on the command line,
  519.         preceding all other options, the target. and the filespecs.
  520.  
  521.  
  522.         Binary search
  523.         -------------
  524.         If you use a hexadecimal byte sequence in your target, or if you
  525.         specify the -b or -B switch, FGREP uses a "binary" mode rather
  526.         than the usual text mode.  In this mode, FGREP is not concerned
  527.         with "lines" of text and can be used to search any file for
  528.         arbitrary sequences of bytes.
  529.  
  530.         The output format is different.  Because there are no "lines" to
  531.         display, FGREP shows the locations in the file where the target
  532.         was found and the sixteen bytes surrounding the find (eight
  533.         before, and eight after).  Here is the output format, split into
  534.         two lines:
  535.  
  536.             nnnnnnnn: n n n n n n n n . n n n n n n n n
  537.                       cccccccc . cccccccc
  538.  
  539.         The initial sequence is the 32-bit file offset where the target
  540.         was found, in hex.  For example,
  541.  
  542.             0001C47A:
  543.  
  544.         indicates that the target was found at file offset 1C47A.
  545.  
  546.         The next two series (n n n ...) represent the eight bytes before
  547.         and after the target (which, logically, occurred at the '.'
  548.         position):
  549.  
  550.             4B 7F 37 42 42 44 FF FF . 20 20 21 48 48 4F 3C 22
  551.  
  552.         The final series (ccc...) represents the same sixteen bytes
  553.         displayed as characters.  Nondisplayable characters are shown as
  554.         periods.
  555.  
  556.         Unlike text searches, binary searches are normally case
  557.         sensitive.  That is, $41 ('A') will not match $61 ('a').  If you
  558.         want a binary search to be case INsensitive ($41 matches both
  559.         $41 and $61), use -B instead of -b.  The normal case sensitive
  560.         switch (-c) is ignored.
  561.  
  562.         These switches are also ignored in binary mode:
  563.  
  564.             -a          ANSI mode
  565.             -l          Show line numbers
  566.             -m/M        "Microsoft" format
  567.             -t          Display found text only
  568.             -v          Inverse search
  569.             -w          Whitespace insensitive
  570.             -Zb         Filter "bell" characters
  571.  
  572.         Also, wildcards are not permitted in string targets when a
  573.         binary search is used.
  574.  
  575.  
  576.         Limiting searches to specified columns
  577.         --------------------------------------
  578.         The -i option specifies an input search field.  You can use this
  579.         if you are only interested in text that appears in certain
  580.         columns of your files.  The syntax of the option is:
  581.  
  582.             -i#[,#]
  583.  
  584.         where the first # is the starting column and the second is the
  585.         ending column.  The second # is optional; if it is not present,
  586.         FGREP will only find your target if it begins in the specified
  587.         starting column.
  588.  
  589.         The first column of each line is column 1.
  590.  
  591.         Examples:
  592.  
  593.             fgrep -i20,30 stuff *.txt
  594.  
  595.               Looks for the word "stuff" in text columns 20 through 30.
  596.  
  597.             fgrep -i1 stuff *.txt
  598.  
  599.               Looks for lines that begin with the word "stuff".
  600.  
  601.             fgrep -i10 stuff *.txt
  602.  
  603.               Looks for lines with the word "stuff" beginning at
  604.               column 10.
  605.  
  606.         In order for text to be "found," it must appear entirely within
  607.         the search field.  Using the first example, the only matches
  608.         would be lines that contain "stuff" beginning in columns 20
  609.         through 26:
  610.  
  611.               1 2 2 2 2 2 2 2 2 2 2 3 3
  612.               9 0 1 2 3 4 5 6 7 8 9 0 1
  613.               s t u f f                   (No match; 's' in col 19)
  614.                 s t u f f                 (Match)
  615.                             s t u f f     (Match)
  616.                               s t u f f   (No match; 'f' in col 31)
  617.  
  618.         Note that using the -i option forces FGREP to use the "slower"
  619.         of its two search techniques (see below).  It will probably
  620.         speed up searches that use the -L, -m/m, -V, or -W options (all
  621.         of which also require the slower search), but it may slow down
  622.         other searches.
  623.  
  624.  
  625.         "Fast" search technique
  626.         -----------------------
  627.         FGREP uses two different search techniques.  Both are fast, but
  628.         one is faster than the other.  The faster search will be used
  629.         UNLESS any of these conditions are met:
  630.  
  631.             - line numbers or "Microsoft" format used (-L or -m/M)
  632.             - the search is reVerse (-v)
  633.             - the search is whitespace insensitive (-w)
  634.             - the target string contains wildcards ("?")
  635.             - the search is limited to specified columns (-i)
  636.  
  637.         For other searches, the "fast" technique is typically 20-40%
  638.         faster than the "slow", although we've seen 70% improvements in
  639.         some cases.
  640.  
  641.         The technique has its roots in searching for unusual (less
  642.         frequently used) characters, so it will make more of a
  643.         difference searching for "squeeze" (q is a little-used letter)
  644.         than it will searching for "eat".
  645.  
  646.  
  647.                    Using your own frequency tables: BUILDFT
  648.                    ----------------------------------------
  649.  
  650.         In most cases, FGREP uses a built-in character frequency table
  651.         to help find strings as fast as possible.  Because FGREP was
  652.         originally intended for use by programmers, this frequency table
  653.         was created by analyzing a great deal of program source code
  654.         written in the C, Pascal, and assembler programming languages.
  655.  
  656.         While the table is pretty good for programmers using the above
  657.         languages, it may not be ideal for your use, because the
  658.         character frequencies in your files may be very different from
  659.         the frequencies in program source code files.  You can use the
  660.         BUILDFT program, which is included with FGREP, to create your
  661.         own frequency tables for FGREP to use, possibly resulting in
  662.         faster searches.
  663.  
  664.         Speed differences between using the default table and custom
  665.         tables depend on several factors; in specific searches, you may
  666.         see a big difference, a small difference, or no detectable
  667.         difference.  In some cases, it's even possible that using the
  668.         default table could be faster than using a custom table.  In
  669.         other words, your mileage may vary.
  670.  
  671.         FGREP does NOT use a character frequency table if your search
  672.         target contains wildcards (? characters).
  673.  
  674.  
  675.         Creating frequency tables
  676.         -------------------------
  677.         To create frequency tables, just run BUILDFT and specify one
  678.         or more filenames (which may include paths and wildcards):
  679.  
  680.               BUILDFT file {file}
  681.  
  682.         The file name(s) specify which files you want BUILDFT to scan.
  683.         It reads these files, counts characters, and stores the
  684.         resulting frequency table in a disk file named FGREP.FT.  For
  685.         example:
  686.  
  687.               BUILDFT *.txt d:\bd\*.bas
  688.  
  689.         This command reads all *.TXT files in the current directory and
  690.         *.BAS in D:\BD, counts characters, and creates a new FGREP
  691.         frequency table in the file FGREP.FT (see below for information
  692.         on how to use the new frequency table).
  693.  
  694.  
  695.         Options
  696.         -------
  697.         There are several options you can use when creating frequency
  698.         tables.  Options are not case-sensitive and may be specified in
  699.         any order.  Multiple options must be separated by at least one
  700.         space.  The options are as follows:
  701.  
  702.         The -R option causes BUILDFT to search subdirectories
  703.         recursively, just like FGREP's -R option.  For example, this
  704.         command counts the characters in all *.TXT files on drives C, D,
  705.         and E:
  706.  
  707.               BUILDFT -r c:\*.txt d:\*.txt e:\*.txt
  708.  
  709.         The -M option causes BUILDFT to merge previous character counts
  710.         with new character counts.  Use this to merge the results of
  711.         multiple BUILDFT runs.  The following series of commands is
  712.         identical in effect to the previous example:
  713.  
  714.               BUILDFT -r c:\*.txt
  715.               BUILDFT -r -m d:\*.txt
  716.               BUILDFT -r -m e:\*.txt
  717.  
  718.         The first command (which does not have the -M option) creates a
  719.         new frequency table from the character counts of TXT files on
  720.         drive C. The second command counts the characters in TXT files
  721.         on drive D; because it uses -M, the new character counts are
  722.         added to the previous counts from drive C.  The third command
  723.         does the same thing for drive E.
  724.  
  725.         The -F option allows you to specify a filename other than
  726.         FGREP.FT for the frequency table file.  For example, this
  727.         command creates a file called C.FFT instead of FGREP.FT:
  728.  
  729.               BUILDFT -fC.FFT -r *.c
  730.  
  731.         Finally, the -D option causes BUILDFT to display the frequency
  732.         table after it has been created:
  733.  
  734.               BUILDFT -d *.c
  735.  
  736.         This command builds the frequency table file and displays the
  737.         results.  The display might look like this:
  738.  
  739.               Cod Chr  Freq    Count
  740.               --- ---  ----    -----
  741.                32     65534   161601
  742.               101  e   6179    24716
  743.                42  t   4350    17400
  744.               ...
  745.  
  746.         The first column is the ASCII code for the character (e.g., the
  747.         ASCII code for the letter 'e' is 101).  The second column is the
  748.         character itself.  The third column is FGREP's frequency factor,
  749.         which is the actual number that FGREP uses.  For all
  750.         characters other than <space> (character 32), the value will
  751.         be between 0 and 32767, with higher numbers representing higher
  752.         frequencies (for technical reasons, the space character
  753.         always has a frequency value of 65534).  The final column shows
  754.         the actual number of occurrences of each character in the
  755.         file(s) scanned.
  756.  
  757.         If you specify -D without any filenames to scan, BUILDFT simply
  758.         displays the contents of an existing frequency table file
  759.         without changing it.  Examples:
  760.  
  761.               BUILDFT -d
  762.               BUILDFD -d -fTEXT.FT
  763.  
  764.         The first command displays the character frequencies from the
  765.         default file, FGREP.FT.  The second command displays the
  766.         frequencies from the file TEXT.FT.
  767.  
  768.  
  769.         Using frequency tables
  770.         ----------------------
  771.         To use a frequency table created by BUILDFT, just run FGREP with
  772.         the -g option, which tells it to "Get" the frequency table from
  773.         FGREP.FT.  For example:
  774.  
  775.               fgrep -g "stuff" *.txt
  776.  
  777.         If the frequency table is in a file other than FGREP.FT, or
  778.         if FGREP.FT isn't in the current directory, specify the
  779.         filename and/or path:
  780.  
  781.               fgrep -gTEXT.FT "stuff" *.txt
  782.               fgrep -gC:\UTIL\FGREP.FT "stuff" *.txt
  783.  
  784.         Note that this method of using custom frequency tables is not
  785.         efficient for searching small files; the extra time required
  786.         to load the frequency table will "drown out" any improvements in
  787.         search speed.
  788.  
  789.  
  790.         Replacing the built-in frequency table
  791.         --------------------------------------
  792.         Alternatively, you can use BUILDFT to permanently replace
  793.         FGREP's built-in table.  This option copies a frequency table
  794.         from a file previously created by BUILDFT into the FGREP program
  795.         file; after you've done this, you don't need to use the -g
  796.         option when you run FGREP.
  797.  
  798.         To do this, just run BUILDFT with the -U option:
  799.  
  800.               BUILDFT -u
  801.  
  802.         This copies the frequency table from the file FGREP.FT (the
  803.         default name) into the FGREP program file, FGREP.COM, replacing
  804.         the built-in frequency table.
  805.  
  806.         Of course, when you use the -U option (which alters the
  807.         FGREP.COM program file), you will want to save a copy of the
  808.         original program file somewhere!
  809.  
  810.         To specify a frequency table file other than FGREP.FT, use the
  811.         -F option (just as you did when you created the table file):
  812.  
  813.               BUILDFT -fTEXT.FT -u
  814.  
  815.         You can also use the -P (Program file) option to specify that
  816.         the name of the FGREP program file is something other than
  817.         FGREP.COM.  For example:
  818.  
  819.               BUILDFT -pFGREPC.COM -fTEXT.FT -u
  820.  
  821.         This command copies the frequency table from TEXT.FT into a copy
  822.         of FGREP named FGREPC.COM.
  823.  
  824.         You can use this feature to build custom versions of FGREP for
  825.         different types of files.  For example:
  826.  
  827.               copy fgrep.com fgrepc.com
  828.               buildft *.c *.h
  829.               buildft -u -pFGREPC.COM
  830.  
  831.         You now have a custom version of FGREP.COM (FGREPC.COM) that has
  832.         a special frequency table just for C program source files (which
  833.         usually have the extensions .C or .H).
  834.  
  835.         When you use -U, the only other options you can use are -P and
  836.         -F; no others are permitted.
  837.  
  838.  
  839.         Notes on FGREP
  840.         --------------
  841.         1. The -f and -s switches are mutually exclusive.  If both are
  842.         specified, the last one will be effective.
  843.  
  844.         2. The -M/m and -s switches are mutually exclusive.  If both
  845.         are specified, the last one will be effective.
  846.  
  847.         3. The -v and -t switches are mutually exclusive.  If both are
  848.         specified, FGREP terminates with an error.
  849.  
  850.         4. The -i and -w switches are mutually exclusive.  If both are
  851.         specified, FGREP terminates with an error.
  852.  
  853.         5. If you specify the -e switch, FGREP will stop processing as
  854.         soon as a nonzero errorlevel is determined.  The -e switch is
  855.         really designed to enable other programs to determine whether or
  856.         not a specific file contains a specific string in as little time
  857.         as possible.  For example, here's an algorithm that will quickly
  858.         'touch' all files that do NOT contain a specified string:
  859.  
  860.                 for file in (*.*) do
  861.                     FGREP -e string file
  862.                     if errorlevel < 1 then touch file
  863.                 end
  864.  
  865.         6. The -s switch is automatically set when input is taken from
  866.         redirected standard input.
  867.  
  868.         7. FGREP optimizes the combination -s0 (suppress headers, no
  869.         text) to -e.
  870.  
  871.         8. If you just want to know which files contain a string, use -0;
  872.         it saves time because the rest of the file (after the first hit)
  873.         is skipped.  The combination -f0 is particularly efficient
  874.         for this as it will simply display a list of files that contain
  875.         the string.
  876.  
  877.         9. There is a maximum line length of 500 characters if any of
  878.         the -V, -W, -L, or -M switches are used; otherwise, the maximum
  879.         line length is about 60K (may be less under low memory
  880.         conditions).
  881.  
  882.         10. FGREP expects standard text files; binary files will yield
  883.         weird results unless you use the -b/B binary switch.  For
  884.         the most part, word processor documents are NOT text files; they
  885.         are special files in proprietary formats that contain a good
  886.         deal of non-text information.
  887.  
  888.         Lines can be terminated by any of CR, LF, or CR+LF.
  889.  
  890.         11. If output is redirected to disk, make sure there is enough
  891.         space available.  The program does not check.
  892.  
  893.  
  894.         A little note from the author
  895.         -----------------------------
  896.         I get lots of calls and emails like this:
  897.  
  898.             I love FGREP because it's so fast.  It outperforms the next
  899.             fastest text search utility I have by two-to-one.  If you
  900.             could just add (regular expressions | boolean searches), it
  901.             would be ideal.
  902.  
  903.         Now, there are lots of text search programs with boolean
  904.         searches and regular expressions out there (including the real
  905.         GREPs).  I use some of them myself.  But one day it occurred to
  906.         me that 95% or more of my searches were very simple (not
  907.         requiring either feature) and that I was probably incurring a
  908.         speed penalty for flexibility that I wasn't using much.  So I
  909.         decided to write a program that would handle only these simpler
  910.         searches, but much faster.
  911.  
  912.         The main reason why FGREP is so fast is that I've been able to
  913.         highly optimize these simple searches.  If I added regular
  914.         expressions or boolean searches, this optimization would not be
  915.         possible, and the main reason for the existence of the program
  916.         (speed) would go away.
  917.  
  918.         So. I'm always glad to get comments and suggestions on FGREP,
  919.         so please keep calling and writing.  But I won't be adding
  920.         regular expressions or boolean searches.  If you need those,
  921.         there are plenty of fancier search programs available (including
  922.         the real grep).  The penalty for greater flexibility is usually
  923.         increased search time.
  924.  
  925.         However, since so many people have asked about boolean searches,
  926.         read on...
  927.  
  928.  
  929.         How to use FGREP for AND/OR searches
  930.         ------------------------------------
  931.         It is quite easy to use FGREP to perform an "and" search
  932.         by simply running it twice, piping the output from the
  933.         first run into the second run.  For example, suppose
  934.         you want to see lines containing both "trace" and "reset"
  935.         in any file with a "C" extension:
  936.  
  937.           fgrep -m "trace" *.c | fgrep "reset"
  938.  
  939.         The first run finds lines containing the word "trace" in
  940.         the C files; the output of this run is them piped into a
  941.         second run, which searches for "reset".  The output of
  942.         this run then will contain only lines with both "trace"
  943.         and "reset".  The -m option in the first run is useful
  944.         when you're searching multiple files (as we are here)
  945.         because it specifies the filename with each output line;
  946.         without this option it would be hard to know which files
  947.         the found lines came from.
  948.  
  949.         Note that "*.C" is not re-specified for the second run.
  950.         You want the input to come from the first run, not from
  951.         the original files.
  952.  
  953.         Even though FGREP runs twice, it's our experience that it's
  954.         still  to do this than to use most of the traditional
  955.         search programs that directly support an AND search.
  956.  
  957.         OR searches (e.g., lines with "trace" OR "reset) are a bit
  958.         more difficult.  Of course, if you don't care about duplicate
  959.         finds, you can simply run FGREP twice (once for each word):
  960.  
  961.               fgrep "trace" *.c > foo
  962.               fgrep "reset" *.c >> foo
  963.               type foo
  964.  
  965.         If you don't want to see duplicate lines, you'll need some
  966.         additional tools.  You'll need a sort program (SORT comes
  967.         with DOS, so that's easy) and a tool to eliminate duplicate
  968.         lines.  There are several of these available in public
  969.         domain and freeware (e.g., "UNIQ").
  970.  
  971.         Here's the basic technique:
  972.  
  973.               fgrep -m "trace" *.c > temp
  974.               fgrep -m "reset" *.c >> temp
  975.               sort < temp | uniq
  976.  
  977.         The two runs of fgrep create a file named TEMP with all lines
  978.         that contain either "trace" or "reset".  The third command
  979.         sorts this file and pipes the sorted lines into UNIQ, which
  980.         eliminates duplicate lines and displays the results.
  981.  
  982.         Version 1.84
  983.         ------------
  984.         Corrects a problem finding an occurrence of the search
  985.           target that occurs at the end of the file.
  986.  
  987.         Version 1.83
  988.         ------------
  989.         Corrects a problem with spurious lines being displayed in
  990.           certain reverse searches (-v option).
  991.  
  992.         Version 1.82
  993.         ------------
  994.         Adds -j and -? options.
  995.         Corrects a problem using BUILDFT to update the FGREP program
  996.           file with a new frequency table (problem in v.1.81 only).
  997.         Sends usage information to stdout instead of stderr.
  998.  
  999.         Version 1.81
  1000.         ------------
  1001.         Adds FGREP environment variable and -Zv option.
  1002.         Adds -R option.
  1003.         Less crashy when used on binary files without -b option.
  1004.         Corrected problem searching files on CD-ROM drives.
  1005.         Corrected problems with -t mode.
  1006.  
  1007.         Version 1.80
  1008.         ------------
  1009.         Adds recursive search (-r option).
  1010.         Adds ability to specify just drive/directory (assumes *.*).
  1011.         Adds -i option to specify search fields.
  1012.         Adds -@, -t, -Za, -Zb, -Zd, and -Zl options.
  1013.         Always includes full path when displaying filenames.
  1014.         Adds user-specified frequency table (-g option).
  1015.         Includes BUILDFT program to create frequency tables.
  1016.         Maximum value for -o option increased to 50000 from 256.
  1017.         Allows -o0 to suppress text display.
  1018.         Corrects a problem in parsing hex targets and allows
  1019.           single-digit hex characters (e.g., $A instead of $0A).
  1020.         Uses character frequency table in all searches unless wildcards
  1021.           are present in the search target.
  1022.         Includes 386-only version of FGREP.COM.
  1023.         Corrects a problem in earlier versions that sometimes caused
  1024.           FGREP to incorrectly report insufficent memory.
  1025.         Now requires DOS 3.0 or later.
  1026.  
  1027.         Version 1.72
  1028.         ------------
  1029.         Fixes problem with DOS 2.x, unable to read files.
  1030.  
  1031.         Version 1.71
  1032.         ------------
  1033.         Adds file lists.
  1034.         Adds file sharing support.
  1035.         Corrects two bugs in binary mode display: displaying data beyond
  1036.             end of file, and skipping bytes immediately after the
  1037.             target.
  1038.  
  1039.         Version 1.70
  1040.         ------------
  1041.         Adds binary search.
  1042.         Adds target concatenation (target+target).
  1043.         Cancels if no file specified and not redirected.
  1044.  
  1045.         Version 1.64
  1046.         ------------
  1047.         Bug fix release only: fix garbage in -M display from 1.63
  1048.  
  1049.         Version 1.63
  1050.         ------------
  1051.         Distinguish between -M (path) and -m (no path) switches.
  1052.         -M/-m and -S now mutually exclusive.
  1053.         Allow search for literal '?' character via '\?'.
  1054.  
  1055.         Version 1.62
  1056.         ------------
  1057.         Added -M switch.
  1058.         Increased max length of lines ("slow" search) from 256 to 500.
  1059.  
  1060.         Version 1.61
  1061.         ------------
  1062.         Fixed a problem with pausing on > 255 hits (-P not specified).
  1063.  
  1064.         Version 1.60
  1065.         ------------
  1066.         Added -P switch.
  1067.         Fixed a problem with tab characters and -O switch.
  1068.  
  1069.         Version 1.59
  1070.         ------------
  1071.         Added -O switch.
  1072.         Altered -L operations to allow for line numbers > 65535.  Line
  1073.         numbers now right justified in a 6-character field.
  1074.  
  1075.         Version 1.58
  1076.         ------------
  1077.         Fixed two problems that were causing endless loops in 1.55-1.57.
  1078.         Added -A switch.
  1079.  
  1080.         Version 1.57
  1081.         ------------
  1082.         Added -X switch.
  1083.  
  1084.         Versions 1.55/1.56
  1085.         -----------------
  1086.         "Fast" search algorithm added (thanks to Dave Angel for the
  1087.             idea and the shove).
  1088.         Fixed problems with redirected input.
  1089.         Forced -v (reVerse) search to show blank lines.
  1090.  
  1091.         Versions 1.50/1.51
  1092.         ------------------
  1093.         These versions contain no new features but are significantly
  1094.         faster than earlier versions.  Standard (case-insensitive)
  1095.         searches run about 40% faster than 1.45 (which was 25-30%
  1096.         faster than 1.40).  "Literal" searches (case-sensitive and
  1097.         spacing-sensitive) are highly optimized and may be as much as
  1098.         70% faster than 1.45.
  1099.  
  1100.         Version 1.45
  1101.         ------------
  1102.         We found a few areas that could be made more efficient.  This
  1103.         version can be as much as 25-30% faster than version 1.40.
  1104.  
  1105.         The -L (line numbers) option was added, and improvements made to
  1106.         parameter parsing such that delimiters are not always necessary.
  1107.  
  1108.  
  1109.         Copyright/License/Warranty
  1110.         --------------------------
  1111.         This document and the program files FGREP.COM and BUILDFT.COM
  1112.         ("the software") are copyrighted by the author.  If you are an
  1113.         individual, the copyright owner hereby licenses you to:  use the
  1114.         software; make as many copies of the program and documentation
  1115.         as you wish; give such copies to anyone; and distribute the
  1116.         software and documentation via electronic means.  There is no
  1117.         charge for any of the above.
  1118.  
  1119.         However, you are specifically prohibited from charging, or
  1120.         requesting donations, for any such copies, however made; and
  1121.         from distributing the software and/or documentation with
  1122.         commercial products without prior permission.  An exception is
  1123.         granted to not-for-profit user's groups, which are authorized to
  1124.         charge a small fee (not to exceed $7) for materials, handling,
  1125.         postage, and general overhead.  NO FOR-PROFIT ORGANIZATION IS
  1126.         AUTHORIZED TO CHARGE ANY AMOUNT FOR DISTRIBUTION OF COPIES OF
  1127.         THE SOFTWARE OR DOCUMENTATION, OR TO INCLUDE COPIES OF THE
  1128.         SOFTWARE OR DOCUMENTATION WITH SALES OF THEIR OWN PRODUCTS.
  1129.  
  1130.         THIS INCLUDES A SPECIFIC PROHIBITION AGAINST FOR-PROFIT
  1131.         ORGANIZATIONS DISTRIBUTING THE SOFTWARE, EITHER ALONE OR WITH
  1132.         OTHER SOFTWARE, AND CHARGING A "HANDLING" OR "MATERIALS" FEE OR
  1133.         ANY OTHER SUCH FEE FOR THE DISTRIBUTION.  NO FOR-PROFIT
  1134.         ORGANIZATION IS AUTHORIZED TO INCLUDE THE SOFTWARE ON ANY MEDIA
  1135.         FOR WHICH MONEY IS CHARGED.  PERIOD.
  1136.  
  1137.         Businesses, institutions, and governmental entities must obtain
  1138.         a specific license agreement from The Cove Software Group in
  1139.         order to use the software.
  1140.  
  1141.         No copy of the software may be distributed or given away without
  1142.         this document; and this notice must not be removed.
  1143.  
  1144.         There is no warranty of any kind, and the copyright owner is not
  1145.         liable for damages of any kind.  By using this free software,
  1146.         you agree to this.
  1147.  
  1148.         The software and documentation are:
  1149.  
  1150.                          Copyright (C) 1985-1995,1997 by
  1151.                              Christopher J. Dunford
  1152.                             The Cove Software Group
  1153.                                  P.O. Box 1072
  1154.                             Columbia, Maryland 21044
  1155.  
  1156.                               Tel: (410) 992-9371
  1157.                              CompuServe: 76703,2002
  1158.                       Internet: 76703.2002@compuserve.com
  1159.